﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessObjects.Objects;
using Persistency.DataAccess;
using System.Data;

namespace Persistency.DAL
{
	public static class PersonDAL
	{
		#region Members

		private const string SavePersonStatement = @"dbo.SavePerson";
		private const string GetPersonStatement = @"dbo.GetPerson";
		private const string GetOrganisationPersonen = @"dbo.GetOrganisationPersonen";

		#endregion

		#region Methods

		public static void SavePerson(PersonObject personObject)
		{
			IDictionary<string, object> parameters = GetParameters(personObject);
			SQLHelper.ExecuteStoredProcedure(SavePersonStatement, parameters);
		}

		#endregion

		#region Functions

		public static PersonObject ConvertToPerson(DataRow row)
		{
			PersonObject personObject = new PersonObject();
			personObject.PersKey = (Int32)row["PersKey"];
			personObject.Nachname = (string)row["Zuname"];

			return personObject;
		}

		private static IDictionary<string, object> GetParameters(PersonObject person)
		{
			IDictionary<string, object> parameters = new Dictionary<string, object>();
			parameters.Add("@inPersKey", person.PersKey );
			parameters.Add("@inNachName", person.Nachname);
			parameters.Add("@inVorname", person.Vorname);
			parameters.Add("@inTitel", person.Titel);

			return parameters;
		}

		#endregion

	}
}
